
//901.股票价格跨度
class StockSpanner {
    int dayi;
    stack<pair<int,int>> st;
public:
    StockSpanner() {
        dayi=0;
    }
    
    int next(int price) {
        //向前找,找第一个大于今天的位置
        dayi++;       //天数+1
        while(!st.empty()&&st.top().first<=price) st.pop();  //在栈中在大于price的位置

        int ret=st.empty()?dayi:dayi-st.top().second;   
        st.push({price,dayi});
        return ret;
    }
};

/**
 * Your StockSpanner object will be instantiated and called as such:
 * StockSpanner* obj = new StockSpanner();
 * int param_1 = obj->next(price);
 */